/* URBAN EXPLORER PROJECT
 * 
 * Author: Karthick Nanmaran (s1051713), School of Informatics, The University of Edinburgh
 * Email: karthicknanmaran@gmail.com
 * 
 * Supervisor: Dr.William Mackaness, 
 * 			   Institute of Geography,
 * 			   School of GeoSciences,
 * 			   The University of Edinburgh.
 * Email: william.mackaness@ed.ac.uk
 * 
 * This code can be found online at http://code.google.com/p/urban-explorers/
*/
package Firstdroid.Gps;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class Statistics extends Activity {

private LocationManager LM;
private LocationListener LL;
private TextView LAT, LONG, ACCURACY, ALTITUDE, BEARING, EXTRAS, PROVIDER, SPEED, TIME;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.statistics);
LAT = (TextView)findViewById(R.id.Latitude);
LONG = (TextView)findViewById(R.id.Longitude);
ACCURACY = (TextView)findViewById(R.id.Accuracy);
ALTITUDE = (TextView)findViewById(R.id.Altitude);
BEARING = (TextView)findViewById(R.id.Bearing);
EXTRAS = (TextView)findViewById(R.id.Extras);
PROVIDER = (TextView)findViewById(R.id.Provider);
SPEED = (TextView)findViewById(R.id.Speed);
TIME = (TextView)findViewById(R.id.Time);

LM = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LL = new MyLocationListener();
LM.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LL);

//Get the current location in start-up
LAT.setText(String.valueOf(LM.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()));

LONG.setText(String.valueOf(LM.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()));

}

private class MyLocationListener implements LocationListener{

public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
LAT.setText(String.valueOf(loc.getLatitude()));
LONG.setText(String.valueOf(loc.getLongitude()));
ACCURACY.setText(String.valueOf(loc.getAccuracy()));
ALTITUDE.setText(String.valueOf(loc.getAltitude()));
BEARING.setText(String.valueOf(loc.getBearing()));
PROVIDER.setText(String.valueOf(loc.getProvider()));
SPEED.setText(String.valueOf(loc.getSpeed()));
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); 
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); 
String x = dateFormatGmt.format((loc.getTime()));
TIME.setText(x);
//TIME.setText(String.valueOf(loc.getTime()));
EXTRAS.setText(String.valueOf(loc.getExtras().getInt("satellites")));
}

public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}

public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}

public void onStatusChanged(String provider,
 int status, Bundle extras) {
// TODO Auto-generated method stub
}
}};

